package com.xb.model.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author lzy
 * @create 2024/10/23 15:48
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserInfoData {
    String firstName;
    String lastName;
    String businessEmail;
    String personalEmails;
    String jobTitle;
    String seniorityLevel;
    String mobilePhone;
    String linkedinUrl;
    String department;
    String contactMetroCity;
    String contactState;
    String companyName;
    String companyDomain;
    String companyPhone;
    String primaryIndustry;
    String primarySic;
    String companyIndustry;
    String companySicCode;
    String companyAddress;
    String companyCity;
    String companyState;
    String companyZip;
    String companyLinkedinUrl;
    String companyRevenue;
    String companyEmployeeCount;
    String businessEmailValidationStatus;

    public void setFieldByIndex(int index, String value) {
        switch (index) {
            case 0: setFirstName(value.trim()); break;
            case 1: setLastName(value.trim()); break;
            case 2: setBusinessEmail(value.trim()); break;
            case 3: setPersonalEmails(value.trim()); break;
            case 4: setJobTitle(value.trim()); break;
            case 5: setSeniorityLevel(value.trim()); break;
            case 6: setDepartment(value.trim()); break;
            case 7:
                // 手机号的特殊处理
                String[] phoneNumbers = value.split(",");
                Set<String> uniquePhones = new HashSet<>();
                for (String phone : phoneNumbers) {
                    String trimmedPhone = phone.replaceAll("\\s+", ""); // 去除所有空格
                    if (!trimmedPhone.isEmpty()) {
                        uniquePhones.add(trimmedPhone); // 添加到 Set 中，自动去重
                    }
                }
                setMobilePhone(String.join(",", uniquePhones));
                break;
            case 8: setLinkedinUrl(removeEmojis(value.trim())); break;  // 在这里去除表情包
            case 9: setContactMetroCity(value.trim()); break;
            case 10: setContactState(value.trim()); break;
            case 11: setCompanyName(value.trim()); break;
            case 12: setCompanyDomain(value.trim()); break;
            case 13: setCompanyPhone(value.trim()); break;
            case 14: setPrimaryIndustry(value.trim()); break;
            case 15: setPrimarySic(value.trim()); break;
            case 16: setCompanyIndustry(value.trim()); break;
            case 17: setCompanySicCode(value.trim()); break;
            case 18: setCompanyAddress(value.trim()); break;
            case 19: setCompanyCity(value.trim()); break;
            case 20: setCompanyState(value.trim()); break;
            case 21: setCompanyZip(value.trim()); break;
            case 22: setCompanyLinkedinUrl(value.trim()); break;
            case 23: setCompanyRevenue(value.trim()); break;
            case 24: setCompanyEmployeeCount(value.trim()); break; // 直接存储字符串
            case 25: setBusinessEmailValidationStatus(value.trim()); break;
            default: throw new IllegalArgumentException("索引不存在");
        }
    }

    /**
     * 移除字符串中的表情符号和非打印字符
     */
    private String removeEmojis(String value) {
        if (value == null || value.isEmpty()) {
            return value;
        }
        // 正则表达式匹配表情符号（包括各种表情符号）
        String emojiRegex = "[\\x{1F600}-\\x{1F64F}\\x{1F300}-\\x{1F5FF}\\x{1F680}-\\x{1F6FF}\\x{1F700}-\\x{1F77F}\\x{1F780}-\\x{1F7FF}\\x{1F800}-\\x{1F8FF}\\x{1F900}-\\x{1F9FF}\\x{1FA00}-\\x{1FA6F}\\x{1FA70}-\\x{1FAFF}\\x{2600}-\\x{26FF}\\x{2700}-\\x{27BF}\\x{2300}-\\x{23FF}\\x{2B50}\\x{2B06}\\x{2194}\\x{25AA}\\x{2B06}\\x{25FE}\\x{261D}\\x{270A}\\x{1F9B0}\\x{1F91D}]";
        Pattern pattern = Pattern.compile(emojiRegex);
        Matcher matcher = pattern.matcher(value);
        return matcher.replaceAll(""); // 去除表情符号
    }
}
